package com.qf.controller;

import com.qf.pojo.*;
import com.qf.service.PlayService;
import com.qf.utils.UplodUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Controller
@RequestMapping(value = "/play")
public class PlayController {

    @Autowired
    PlayService playService;

    @Autowired
    UplodUtils uplodUtils;

    //删除，注销账号
    @PostMapping(value = "/del")
    @ResponseBody
    public BaseResp del(@RequestBody Play play){
        return playService.del(play.getId());
    }

    //修改个人信息
    @PostMapping(value = "/update")
    @ResponseBody
    public BaseResp update(@RequestBody Play play){
        return playService.update(play);
    }

    @PostMapping(value = "/findOne")
    @ResponseBody
    public BaseResp findOne(@RequestBody Map map){
        return playService.findOne(map.get("playname").toString());
    }

    //陪玩上传图片
    @PostMapping(value = "/u")
    @ResponseBody
    public String uplod(@RequestParam("file") MultipartFile multipartFile){
        return uplodUtils.upload(multipartFile);
    }

    //陪玩查所有
    @PostMapping(value = "/findAll")
    @ResponseBody
    public BaseResp findAll(@RequestBody  Map map){
        return playService.findAll(map.get("gname").toString(), Integer.valueOf(map.get("page").toString()),Integer.valueOf(map.get("size1").toString()));
    }

    //陪玩修改价格
    @PostMapping(value = "/updateprice")
    @ResponseBody
    public BaseResp updateprice(@RequestBody PlayGame playGame){
        return playService.updateprice(playGame);
    }

    //查看所有游戏
    @PostMapping(value = "/findGame")
    @ResponseBody
    public BaseResp findgame(){
        return playService.findGame();
    }

    //陪玩修改订单状态
    @PostMapping(value = "/upo")
    @ResponseBody
    public BaseResp upo(@RequestBody Orders orders){
        return playService.upo(orders);
    }

    //陪玩查自己会的游戏
    @PostMapping(value = "/findplaygame")
    @ResponseBody
    public BaseResp findplaygame(@RequestBody Map map){
        Integer pid = Integer.valueOf(map.get("pid").toString());
       return playService.findplaygame(pid);
    }

    //陪玩登录
    @PostMapping(value = "/login")
    @ResponseBody
    public BaseResp login(@RequestBody Play play){
        return playService.login(play);
    }
}
